#!/usr/bin/python

import time
import threading


Stack = 0
my_lock = threading.RLock()
num  = 0
class Lock_my(threading.Thread):
    def __init__(self,name):
        self.name = name
        threading.Thread.__init__(self)
        
    def run(self):
        global num
        while True:
            my_lock.acquire()
            print '\nThread %s locked ,Number : %d '%(self.name,num)
            if num >= 4:
                my_lock.release()
                print '\n Tread %s released , NUmber : %d ' % (self.name,num)
                break
            num+=1
            print '\n Tread %s released ,number : %d ' %(self.name,num)
            my_lock.release()

def test():
    thread1 = Lock_my("A")
    thread2 = Lock_my("b")
    thread1.start()
    thread2.start()
    
if __name__ == "__main__":
    test()
